package protocol.transactions;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;
import protocol.meta.AppInfoDetail;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.netease.http.THttpRequest;


public class TransactionGetInfoDetail extends XoneBaseTransaction {
    private String mInfoId;

    public TransactionGetInfoDetail(String infoId) {
        super(TRANSACTION_TYPE_GETINFODETAIL);
        
        mInfoId = infoId;
    }

    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        if (obj instanceof JsonElement) {
            AppInfoDetail infoDetail = null;
            try {
                JsonElement jsonObj = ((JsonElement)obj).getAsJsonObject().get("info");
                Gson gson = new Gson();
                infoDetail = gson.fromJson(jsonObj, AppInfoDetail.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
            notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, infoDetail);
        }
    }
    
    @Override
    public void onTransact() {
        THttpRequest request = null;
        request = XoneProtocol.getInstance().createGetInfoDetailRequest(mInfoId);
        sendRequest(request);
    }

}
